package cooperated

import (
	"fmt"

	"gddgame.cc/galaxy/common/namespaces/cooperate"
	"gddgame.cc/galaxy/common/namespaces/cooperate/structure"
	"gddgame.cc/galaxy/utils/serialize"
)

func (logic *TypeMap) Touch(info *structure.ScheduleInfo, content *cooperate.TouchScheduleContent) {
	slot := serialize.GetSlot()
	switch content.Type {
	case AttackLogicType:
		// 运行攻击
		var attack AttackLogic
		if err := slot.Set(&attack); err != nil {
			fmt.Println("touch attack", err)
		} else if err := slot.Unmarshal(content.Logic); err != nil {
			fmt.Println("touch attack", err)
		} else {
			logic.Attack(info, content, &attack)
		}
	case ListenLogicType:
		// 驻守，防守
		var listen ListenLogic
		if err := slot.Set(&listen); err != nil {
			fmt.Println("touch listen", err)
		} else if err := slot.Unmarshal(content.Logic); err != nil {
			fmt.Println("touch listen", err)
		} else {
			logic.Listen(info, &listen)
		}
	case SearchLogicType:
		// 探索不可见
		var search SearchLogic
		if err := slot.Set(&search); err != nil {
			fmt.Println("touch search", err)
		} else if err := slot.Unmarshal(content.Logic); err != nil {
			fmt.Println("touch search", err)
		} else {
			logic.Search(info, &search)
		}
	case TauntLogicType:
		// 强制目标攻击自己
		var taunt TauntLogic
		if err := slot.Set(&taunt); err != nil {
			fmt.Println("touch taunt", err)
		} else if err := slot.Unmarshal(content.Logic); err != nil {
			fmt.Println("touch taunt", err)
		} else {
			logic.Taunt(info, &taunt)
		}
	case SnipeLogicType:
		// 狙击
		var snipe SnipeLogic
		if err := slot.Set(&snipe); err != nil {
			fmt.Println("touch hold", err)
		} else if err := slot.Unmarshal(content.Logic); err != nil {
			fmt.Println("touch hold", err)
		} else {
			logic.Snipe(info, &snipe)
		}
	case HoldLogicType:
		// 据点占领
		var hold HoldLogic
		if err := slot.Set(&hold); err != nil {
			fmt.Println("touch hold", err)
		} else if err := slot.Unmarshal(content.Logic); err != nil {
			fmt.Println("touch hold", err)
		} else {
			logic.Hold(info, &hold)
		}
	case SpeedTeleportLogicType:
		var speedTeleport SpeedTeleportLogic
		if err := slot.Set(&speedTeleport); err != nil {
			fmt.Println("touch speedTeleport", err)
		} else if err := slot.Unmarshal(content.Logic); err != nil {
			fmt.Println("touch speedTeleport", err)
		} else {
			logic.SpeedTeleport(info, &speedTeleport)
		}
	case CustomLogicType:
		logic.CustomTouch(info, content)
	}
	slot.Release()
}
